package com.tadpole.music.holder.home;

import android.app.Activity;
import android.view.View;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.tadpole.music.R;
import com.tadpole.music.adapter.base.BaseAdapter;
import com.tadpole.music.bean.home.NewInfoListBean;
import com.tadpole.music.config.Constant;
import com.tadpole.music.holder.base.BaseViewHolder;
import com.tadpole.music.utils.Mutils;
import com.tadpole.music.utils.NoDoubleClickListener;
import com.tadpole.music.view.widget.XCRoundRectImageView;

import java.text.ParseException;
import java.util.List;

/**
 * Created By 孙岩
 * on 2020/12/5
 */
public class NewInfoListViewHolder extends BaseViewHolder {
    private View itemView;
    private BaseAdapter.OnItemClickListener onItemClickListener;
    private Activity activity;
    private List<NewInfoListBean.DataBeanX.DataBean> list;
    private XCRoundRectImageView ivImage;
    private TextView tvTitle;
    private TextView tvTime;

    public NewInfoListViewHolder(Activity activity, View itemView, BaseAdapter.OnItemClickListener onItemClickListener, List<NewInfoListBean.DataBeanX.DataBean> list) {
        super(itemView);
        this.itemView = itemView;
        this.activity = activity;
        this.onItemClickListener = onItemClickListener;
        this.list = list;
    }

    @Override
    public void init(final int position) {
        ivImage = itemView.findViewById(R.id.ivImage);
        tvTitle = itemView.findViewById(R.id.tvTitle);
        tvTime = itemView.findViewById(R.id.tvTime);

        if (list.get(position).getThumb().equals("")) {
            ivImage.setVisibility(View.GONE);
        } else {
            ivImage.setVisibility(View.VISIBLE);
            RequestOptions requestOptions = new RequestOptions()
                    .placeholder(R.mipmap.app_icon)
                    .error(R.mipmap.app_icon)
                    .priority(Priority.HIGH)
                    .diskCacheStrategy(DiskCacheStrategy.ALL);

            Glide.with(activity).load(Constant.IMAGE_HEAD + list.get(position).getThumb()).apply(requestOptions).into(ivImage);
        }

        tvTitle.setText(list.get(position).getTitle());

        tvTime.setText(list.get(position).getCreated_at());

        itemView.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                onItemClickListener.onItemClick(itemView, position);
            }
        });
    }
}
